package com.project.base.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PageCodeUtil {

    public static String getPageCode(String pageName, String path)
            throws IOException {
        pageName = pageName.trim();
        Properties prop = getProperties(path);
        for (String key : prop.stringPropertyNames()) {
            if (prop.get(key).equals(pageName)) {
                return key;
            }
        }

        return null;
    }

    public static String getPageName(String pageCode, String path)
            throws IOException {
        Properties prop = getProperties(path);
        return prop.getProperty(pageCode, pageCode);
    }

    public static Properties getProperties(String path) {
        Properties properties = new Properties();
        InputStream inputStream = PageCodeUtil.class.getResourceAsStream(path);
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return properties;
    }
}
